package com.handydata.antifraud.rule.funcs;

import com.handydata.antifraud.enums.RuleNonQuntityValueConvertEnum;
import com.handydata.antifraud.to.RiskInputTO;
import com.handydata.antifraud.to.RiskMiddleTO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

@Component
public class CalcMacPattern extends CalculateAdapter {
    private static final Logger logger = LoggerFactory.getLogger(CalcXYDPI.class);

    @Override
    public void doCalc(RiskInputTO riskInputTO, RiskMiddleTO riskMiddleTO) {
        logger.info("开始计算mac是否符合正则^\\\\s*([0-9a-fA-F]{2,2}:){5,5}[0-9a-fA-F]{2,2}\\\\s*$\" mac {}",riskInputTO.getDeviceNic());
        Pattern pattern = Pattern.compile("^\\s*([0-9a-fA-F]{2,2}:){5,5}[0-9a-fA-F]{2,2}\\s*$");
        Matcher matcher = pattern.matcher(riskInputTO.getDeviceNic());
        if(matcher.matches()) {
            riskMiddleTO.setCalAUniR001Result(RuleNonQuntityValueConvertEnum.MATCH_FAIL.getCode());
        } else {
            riskMiddleTO.setCalAUniR001Result(RuleNonQuntityValueConvertEnum.MATCH_OK.getCode());
        }
    }
}
